# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
from get_proportion import get_proportion
from get_weight_by_entropy import get_weight_by_entropy
from get_weight_by_msd import get_weight_by_msd
from load_dataframe import load_dataframe
from normalizing import normalizing
import pandas as pd

from plot_line import plot_line


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
# 昆明新型城镇化评价指标统计-计算 新型城镇化评价指标
# 昆明生态环境评价指标统计-计算 生态环境评价指标
csh_file = 'data/年鉴统计数据/地级市数据/最终成果/新型城镇化与生态环境评价指标-昆明市.xlsx'
sheet_name = '生态环境评价指标'
# 加载数据
dataframe = load_dataframe(csh_file, sheet_name)

# 归一化处理
normal_df = normalizing(dataframe)

# 求单个数值占整个序列数值之和的比重
proportion_df = get_proportion(normal_df)

# 熵权法确定指标权重
weight_ent = get_weight_by_entropy(proportion_df)

# 均方差决策法确定指标权重
weight_msd = get_weight_by_msd(proportion_df)

# 求综合权重
weights = 0.5 * (weight_ent + weight_msd)
weights.name = '综合权重'
print('----------综合权重----------')
print(weights)

# 计算指标得分
scores_df = pd.DataFrame(columns=normal_df.columns, index=normal_df.index)
for i in weights.index:
    scores_df[i] = weights[i] * normal_df[i]
print('----------指标得分----------')
print(scores_df)

# 计算指标综合得分
scores_df['综合得分'] = scores_df.sum(axis=1)
print('----------综合得分----------')
print(scores_df)

title = '昆明生态环境评价得分演变趋势'
# 保存为excel
scores_df.to_excel('昆明生态环境评价得分演变趋势.xlsx')
# 会折线图
plot_line(scores_df, title)

